package com.wangzhenyu.common.base.delegate

import android.content.Context
import com.wangzhenyu.common.view.dialog.LoadingDialog

/**
 * Desc   : LoadingDialog 操作类接口定义
 */
interface LoadingDelegate {

    fun showDialogLoading(content: String?)
    fun hideDialogLoading()
}

/**
 * LoadingDialog 委托类
 */
@Suppress("UNUSED")
class DefaultLoadingDelegate(private val mContext: Context) : LoadingDelegate {

    private var mLoadingDialog: LoadingDialog? = null

    override fun showDialogLoading(content: String?) {
        if (mLoadingDialog == null) {
            mLoadingDialog = LoadingDialog.Builder(mContext)
                .setCancelable(true)
                .setCancelOutside(false)
                .create()
        }
        if (!mLoadingDialog!!.isShowing) {
            mLoadingDialog?.setLoadingText(content)
            mLoadingDialog?.show()
        }
    }

    override fun hideDialogLoading() {
        if (mLoadingDialog != null && mLoadingDialog!!.isShowing) {
            mLoadingDialog?.dismiss()
            mLoadingDialog = null
        }
    }
}